<template>
    <div>
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>
                    <div class="contentsize">对账信息</div>
                </el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <div class="handle-box">
                <el-form ref="form" :model="form" label-width="80px" :inline="true" size="mini">
                    <el-form-item label="对账状态:">
                        <div style="width: 190px">
                            <el-select v-model="form.dzzt" placeholder="请选择对账状态" clearable @change="onSearch">
                                <el-option v-for="item in dzztlist" :key="item.code" :label="item.name" :value="item.code"> </el-option>
                            </el-select>
                        </div>
                    </el-form-item>
                    <el-form-item label="承租单位:">
                        <div style="width: 190px">
                            <el-input v-model="form.czr" placeholder="请输入承租单位" clearable @keyup.enter.native="onSearch"></el-input>
                        </div>
                    </el-form-item>
                    <el-form-item label="合同编号:">
                        <div style="width: 190px">
                            <el-input v-model="form.htbh" placeholder="请输入合同编号" clearable @keyup.enter.native="onSearch"></el-input>
                        </div>
                    </el-form-item>
                    <el-form-item label="档案编号:">
                        <div style="width: 190px">
                            <el-input v-model="form.dabh" placeholder="请输入档案编号" clearable @keyup.enter.native="onSearch"></el-input>
                        </div>
                    </el-form-item>
                    <el-form-item label="开始日期:">
                        <div style="width: 190px">
                            <el-date-picker
                                type="date"
                                placeholder="选择开始日期"
                                v-model="form.startTime"
                                style="width: 100%"
                                value-format="yyyy-MM-dd"
                                @change="onSearch"
                            ></el-date-picker>
                        </div>
                    </el-form-item>
                    <el-form-item label="结束日期:">
                        <div style="width: 190px">
                            <el-date-picker
                                type="date"
                                placeholder="选择结束日期"
                                v-model="form.endTime"
                                style="width: 100%"
                                value-format="yyyy-MM-dd"
                                @change="onSearch"
                            ></el-date-picker>
                        </div>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click="onSearch" icon="el-icon-search" class="searchcolor">查询</el-button>
                        <el-button @click="reSearch" icon="el-icon-refresh" class="searchcolor">重置</el-button>
                        <el-button type="primary" @click="downloadlist" icon="el-icon-download" class="searchcolor">导出</el-button>
                    </el-form-item>
                </el-form>
            </div>
            <!-- max-height="330" -->
            <!-- @selection-change="handleSelectionChange" -->
            <!-- <el-button type="primary" @click="yzyclick" class="searchcolor" style="margin-bottom: 10px;">报账</el-button> -->
            <el-table
                :data="tableData"
                style="width: 100%"
                :header-cell-style="tableHeaderColor"
                :row-style="tablerowColor"
                :row-class-name="tableRowClassName"
                :cell-style="tablecellColor"
                border
                :max-height="maxHeight"
            >
                <!-- <el-table-column type="selection" width="55" :selectable="selectable"></el-table-column> -->
                <el-table-column prop="htbh" label="合同编号" align="center" width="160"> </el-table-column>
                <el-table-column prop="dabh" label="档案编号" align="center" width="240" :show-overflow-tooltip="true"> </el-table-column>
                <el-table-column prop="fwdz" label="房屋地址" align="center" width="280" :show-overflow-tooltip="true"> </el-table-column>
                <el-table-column prop="czr" label="承租单位" align="center" width="280"> </el-table-column>
                <el-table-column prop="skrq" label="交款日期" align="center" width="100">
                    <template slot-scope="scope">
                        {{ scope.row.jkrq ? scope.row.jkrq.split(' ')[0] : '' }}
                    </template>
                </el-table-column>
                <el-table-column prop="dzzt" label="对账状态" align="center">
                    <template slot-scope="scope">
                        {{
                            scope.row.dzzt == '0'
                                ? '未报账'
                                : scope.row.dzzt == '1'
                                ? '退回'
                                : scope.row.dzzt == '2'
                                ? '通过'
                                : scope.row.dzzt == '3'
                                ? '单位待审核'
                                : scope.row.dzzt == '4'
                                ? '经租待审核'
                                : scope.row.dzzt == '5'
                                ? '财务待审核'
                                : ''
                        }}
                    </template>
                </el-table-column>
                <el-table-column prop="jfk" label="交返款" align="center">
                    <template slot-scope="scope">
                        {{ scope.row.jfk == '1' ? '交款' : scope.row.jfk == '2' ? '返款' : '' }}
                    </template>
                </el-table-column>
                <el-table-column prop="ysqje" label="已收金额" align="center" width="100"> </el-table-column>
                <el-table-column prop="ysje" label="预收金额" align="center" width="100"> </el-table-column>
                <el-table-column prop="yzyje" label="预转已金额" align="center" width="100"> </el-table-column>
                <el-table-column prop="jqtje" label="缴其他金额" align="center" width="100"> </el-table-column>
                <el-table-column prop="sqje" label="税前金额" align="center" width="100"> </el-table-column>
                <el-table-column prop="she" label="税额" align="center" width="100"> </el-table-column>
                <el-table-column prop="shje" label="税后金额" align="center" width="100"> </el-table-column>
                <el-table-column prop="zjlb" label="收租方式" align="center"> </el-table-column>
                <el-table-column prop="zph" label="支票号" align="center"> </el-table-column>
                <el-table-column prop="jyjje" label="缴（退）押金金额" align="center" width="140"> </el-table-column>
                <el-table-column prop="tkje" label="退款金额" align="center" width="100"> </el-table-column>
                <el-table-column prop="zsje" label="增收金额" align="center" width="100"> </el-table-column>
                <el-table-column prop="bz" label="备注" align="center" :show-overflow-tooltip="true"> </el-table-column>
                <el-table-column label="操作" width="140" align="center" fixed="right">
                    <template slot-scope="scope">
                        <!-- target="_blank" -->
                        <router-link :to="{ name: 'dzdetailjlb', query: { id: scope.row.id } }">
                            <el-button type="text" size="small">查看</el-button>
                        </router-link>
                        <router-link
                            target="_blank"
                            :to="{
                                path: '/dzprintfilejlb',
                                query: { czr: scope.row.czr, jkrq: scope.row.jkrq, zjlb: scope.row.zjlb, sdn: scope.row.ysqje }
                            }"
                        >
                            <el-button type="text" size="small" style="margin-left: 12px">交款单</el-button>
                        </router-link>
                        <el-button
                            type="text"
                            size="small"
                            @click="deleteClick(scope.row)"
                            style="color: red; margin-left: 12px"
                            v-if="scope.row.dzzt == 1"
                            >删除</el-button
                        >
                        <!-- <el-button type="text" size="small" @click="deleteClick(scope.row)"
                            style="color: red;margin-left: 12px;"
                            v-if="scope.row.dzzt == 0 || scope.row.dzzt == 3">删除</el-button> -->
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination" style="float: right">
                <el-pagination
                    background
                    layout="total,sizes,prev, pager, next,jumper"
                    :total="total"
                    :current-page.sync="current"
                    :page-sizes="[10, 20, 30, 40, 50, 100]"
                    :page-size="pageSize"
                    @current-change="handleCurrentChange"
                    @size-change="handleSizeChange"
                >
                </el-pagination>
            </div>
        </div>
    </div>
</template>

<script>
import { jlbdzlist, dzdelete, dzdeletejlb, dzupdate, wtdwlist, exportdzlistjlb, getfgyList } from '@/api/index';
import valueList from '@/components/common/valueList.vue';
export default {
    name: 'jlbdzlist',
    data() {
        return {
            getfgyShow: false, //房管员判断
            fgylist: [], //房管员列表
            dzztlist: valueList.dzztlist1, //对账状态
            wtdwlists: [], //委托单位
            wtdwform: {
                create_time: '', //创建时间 ,
                current: 1, //第几页 ,
                dwbh: '', //单位编号 ,
                dwmc: '', //单位名称 ,
                id: '', //id ,
                lxdh: '', // 联系电话 ,
                lxr: '', //联系人 ,
                pageSize: 999, //每页数量 ,
                status_code: 1, //1正常 2删除
                tght: '', //托管合同 ,
                yyzz: '' //营业执照
            },
            total: 0,
            current: 1,
            pageSize: 10,
            form: {
                bjqje: '', // 补旧欠金额 ,
                bz: '', // 备注 ,
                create_name: '', // 创建人 ,
                create_name_id: '', // 创建人id ,
                create_time: '', // 创建时间 ,
                current: 1, // 第几页 ,
                czr: '', // 承租单位 ,
                dabh: '', // 档案编号 ,
                dzzt: null, // 对账状态 0：未报账 1：已报账 2：通过 3：退回,
                htbh: '', // 合同编号 ,
                id: '',
                jfk: null, // 交返款 1：交款 2：返款,
                jkrq: '', // 交款日期 ,
                jqtje: '', // 缴其他金额 ,
                pageSize: 10, // 每页数量 ,
                she: '', // 税额 ,
                shje: '', // 税后金额 ,
                sqje: '', // 税前金额(实收金额),
                status_code: '1', // 1正常 2删除,
                update_name: '', // 修改人 ,
                update_name_id: '', // 修改人id ,
                update_time: '', // 修改时间 ,
                ysje: '', // 预收金额（转入预收金额） ,
                ysqje: '', // 已收金额 ,
                yzyje: '', // 预转已金额（预收转为已收金额） ,
                zjlb: '', // 收租方式 ,
                zph: '', // 支票号
                fgy: '',
                type: '1',
                role: this.$store.getters.role,
                startTime: '',
                endTime: ''
            },
            tableData: [],
            multipleSelection: [], //确认选中列表
            maxHeight: null
        };
    },
    components: {},
    computed: {
        // 判断变色
        getcolorred(htzt) {
            console.log(htzt);
            return (htzt) => {
                if (htzt == '正常') {
                    return { color: '#19BE6B', fontWeight: 700 };
                } else if (htzt == '已经到期') {
                    return { color: '#D9001B', fontWeight: 700 };
                } else if (htzt == '即将到期') {
                    return { color: '#FF9900', fontWeight: 700 };
                } else if (htzt == '未签合同') {
                    return { color: '#409ee1', fontWeight: 700 };
                }
            };
        }
    },
    methods: {
        //复选框禁用
        selectable(row, rowIndex) {
            //索引是从0开始，条件1是指只有第2行数据不被禁用
            console.log(row, rowIndex);
            if (row.dzzt == '0') {
                return true; //不禁用
            } else if (row.dzzt == '1') {
                return true; //不禁用
            } else {
                return false; //禁用
            }
        },
        // 列表样式
        tableHeaderColor({ row, column, rowIndex, columnIndex }) {
            if (rowIndex === 0) {
                return 'background:linear-gradient(to bottom, #008A94,#0ae2f2)!important;color:#ffffff;font-size:14px;';
            }
        },
        tablerowColor({ row, rowIndex }) {
            return 'height: 42px;font-size:14px;color:black';
        },
        tablecellColor() {
            return 'font-weight:700;color:#000000;border-color:#c0c0c0';
        },
        tableRowClassName({ row, rowIndex }) {
            if (rowIndex % 2 != 0) {
                return 'success-row'; //这是类名
            } else {
                return '';
            }
        },
        // 换页
        handleCurrentChange(val) {
            this.current = val;
            this.form.current = val;
            this.jlbdzlist(this.form);
            console.log(val);
        },
        // 每页条数
        handleSizeChange(val) {
            this.current = 1;
            this.pageSize = val;
            this.form.pageSize = val;
            this.jlbdzlist(this.form);
            console.log(val);
        },
        // 搜索
        onSearch() {
            this.current = 1;
            this.form.current = 1;
            this.jlbdzlist(this.form);
            console.log('搜索');
        },
        // 重置
        reSearch() {
            this.current = 1;
            this.pageSize = 10;
            this.form = {
                bjqje: '', // 补旧欠金额 ,
                bz: '', // 备注 ,
                create_name: '', // 创建人 ,
                create_name_id: '', // 创建人id ,
                create_time: '', // 创建时间 ,
                current: 1, // 第几页 ,
                czr: '', // 承租单位 ,
                dabh: '', // 档案编号 ,
                dzzt: null, // 对账状态 0：未报账 1：已报账 2：通过 3：退回,
                htbh: '', // 合同编号 ,
                id: '',
                jfk: null, // 交返款 1：交款 2：返款,
                jkrq: '', // 交款日期 ,
                jqtje: '', // 缴其他金额 ,
                pageSize: 10, // 每页数量 ,
                she: '', // 税额 ,
                shje: '', // 税后金额 ,
                sqje: '', // 税前金额(实收金额),
                status_code: '1', // 1正常 2删除,
                update_name: '', // 修改人 ,
                update_name_id: '', // 修改人id ,
                update_time: '', // 修改时间 ,
                ysje: '', // 预收金额（转入预收金额） ,
                ysqje: '', // 已收金额 ,
                yzyje: '', // 预转已金额（预收转为已收金额） ,
                zjlb: '', // 收租方式 ,
                zph: '', // 支票号
                type: '1', //
                role: this.$store.getters.role,
                startTime: '',
                endTime: ''
                // fgy:this.$store.getters.role=='10011'?this.$store.getters.userId:''
            };
            this.jlbdzlist(this.form);
            console.log('搜索');
        },
        // 添加
        addnew() {
            this.$router.push({
                name: 'addproject',
                path: '/addproject'
            });
        },
        // 删除
        deleteClick(e) {
            console.log(e);
            this.$confirm('确定删除此条信息吗？')
                .then(() => {
                    let data = e.id;
                    dzdeletejlb(data).then((res) => {
                        if (res.code == 200) {
                            this.jlbdzlist(this.form);
                            this.$message.success('删除成功');
                        }
                    });
                })
                .catch(() => {
                    this.$message.success('删除取消');
                });
        },
        // 对账列表
        jlbdzlist(data) {
            jlbdzlist(data).then((res) => {
                if (res.code == 200) {
                    this.tableData = res.data.records;
                    this.total = res.data.total;
                } else {
                    this.tableData = [];
                    this.total = 0;
                }
            });
        },
        // 对账状态确认
        dzupdate(data) {
            dzupdate(data).then((res) => {
                this.$message.success('已提交');
                this.jlbdzlist(this.form);
            });
        },
        // 多条报账点击事件
        handleSelectionChange(val) {
            console.log('val', val);
            this.multipleSelection = val;
        },
        // 报账按钮
        yzyclick() {
            this.$confirm(`确定对所选数据执行报账操作吗？`)
                .then(() => {
                    let data = {
                        dzzt: '1', //对账状态 0：未报账 1：已报账 2：通过 3：退回
                        jflist: this.multipleSelection
                    };
                    console.log('报账', data);
                    this.dzupdate(data);
                    this.$message.success('操作成功');
                })
                .catch(() => {
                    this.$message('操作取消');
                });
        },
        // 委托单位列表
        wtdwlist(data) {
            wtdwlist(data).then((res) => {
                if (res.code == 200) {
                    this.wtdwlists = res.data.records;
                }
            });
        },
        // 导出
        downloadlist() {
            exportdzlistjlb(this.form).then((res) => {
                console.log(res);
                const link = document.createElement('a');
                let blob = new Blob([res], {
                    type: 'application/vnd.ms-excel'
                });
                link.style.display = 'none';
                //设置连接
                link.href = URL.createObjectURL(blob);
                link.download = '对账导出文件';
                document.body.appendChild(link);
                //模拟点击事件
                link.click();
                console.log(res);
            });
        },
        // 获取房管员列表
        getfgyList() {
            let data = {};
            getfgyList(data).then((res) => {
                if (res.code == 200) {
                    this.fgylist = res.data;
                    if (this.$store.getters.role == '10011') {
                        console.log(this.$store.getters.userId);
                        this.form.fgy = this.$store.getters.userId;
                        this.getfgyShow = true;
                    } else {
                        this.getfgyShow = false;
                    }
                    this.jlbdzlist(this.form);
                    console.log(res.data);
                } else {
                    this.$message.error = '获取数据失败！！';
                }
            });
        }
    },
    mounted() {
        this.$nextTick(() => {
            // window.innerHeight 浏览器窗口的可见高度，下面的 420 是除了table最大高度的剩余空间。
            this.maxHeight = window.innerHeight - 400;
        });
        // 获取房管员列表
        // this.getfgyList()
        this.jlbdzlist(this.form);
        // this.wtdwlist(this.wtdwform)
    }
};
</script>

<style scoped>
.container {
    /* height: calc(100vh - 260px); */
    overflow: hidden;
}

.crumbs {
    background-color: #fff;
    padding: 20px 20px;
}

.indexTitle {
    margin-bottom: 20px;
}

.contentsize {
    font-size: 18px;
    font-weight: 700;
}

.handle-box {
    overflow: hidden;
}

/* 新增按钮 */
.addcolor {
    margin-bottom: 10px;
}
</style>
<style>
.success-row {
    background-color: #eaf3fb !important;
}
</style>

